<div class="deploy_form">

    <div class="modal-header ">
        <button aria-hidden="true" type="button " class="close close-x" data-dismiss="modal" onclick="empty_app_config_dialog();"></button>
        <h3><?php echo $this->language->get('text_app_config');?></h3>
    </div>
    <div style="padding: 10px;">
            <div class="app_config_left">
                <h2><?php echo $this->language->get('text_app_basic_config');?></h2>
                <label class="control-label"><?php echo $this->language->get('text_item_app_name');?><span class="required">*</span></label>
                <input type="text" value="<?php echo $app_name;?>" name="app_name"/><br/>
				

                <input type="hidden"  id="region" name="region" value="<?php echo $region;?>">
                <label class="control-label"><?php echo $this->language->get('text_item_os_type');?><span class="required">*</span></label>
                <select id="os_type" name="os_type">
                    <?php foreach($os_types as $key=>$result){ ?>
                    <option value="<?php echo $key?>" <?php if($os_type==$key){
                    echo 'selected="selected"';  } ?> ><?php echo $result?></option>
                    <?php }?>
                </select>
                <label class="control-label"><?php echo $this->language->get('text_item_instance_type');?><span class="required">*</span></label>
                <select id="host_type" name="host_type">
                    <?php foreach($host_types as $key=>  $result){ ?>
                    <option value="<?php echo $key?>"  <?php if($host_type==$key){
                    echo 'selected="selected"';  } ?> ><?php echo $result?></option>
                    <?php }?>
                </select>

                <div class="hidden" >

								<label class="control-label">登录方式<span class="required">*</span></label>

								<div class="app_config_left" >
                                    <select  data-placeholder="无" id="app_select_login_type" >



											<option value="password" selected="selected">密码方式</option>

											<option value="ssh_public_key">SSH密钥对</option>

									</select>
								</div>

				</div>

				 <div class="hide" id="app_login_password">
								<div class="app_config_left">
								  <label class="control-label"><?php echo $this->language->get('text_item_administrator_password');?><span class="required">*</span></label>
               					 <input type="text" value="<?php echo $super_password;?>" name="super_password"/>

								</div>
				</div>

				<div class="hide" id="app_login_sshkey" style="display: none;" disabled="disabled">

					<label class="control-label">SSH密钥对<span class="required">*</span></label>

					<div class="app_config_left">

						<select class="span8 m-wrap" data-placeholder="无" id="app_select_sshkey_name" name="ssh_key" tabindex="1">

								<option value="">无</option>

						</select>
                        <label><i>若无SSH密钥对选择，请先创建新的SSH密钥对</i></label>

					</div>

				</div>

            </div>
            <div class="app_config_right">

                <img src="<?php echo $thumb;?>" />
                <?php echo $this->language->get('text_app_config_estimate');?>:<span id="price_1"><?php echo $price;?></span>
                <input id="price_2" type="hidden" value="<?php echo $price;?>" name="price">

            </div>
            <div style="clear: both;"></div>
        <hr>
            <h2 style="margin-top: 20px;"><?php echo $this->language->get('text_app_action_config');?></h2>
            <table class="control_block">
            <?php if($web_control){ ?>
                <tr>
                    <td style="width: 150px;">
                        <label>web<?php echo $this->language->get('text_app_action_action_text1');?>: </label>
                        <input type="checkbox" name="web_control_status"  value="1" <?php if($web_control_status) { ?> checked="checked" <?php } ?>>
                    </td>
                    <td>
                        <label class="control-label"><?php echo $this->language->get('text_app_action_action_text2');?> : </label>
                        <input type="text" <?php if($web_control_alter){ ?> disabled='disabled' <?php } ?> name="web_control_port_mapping" value="<?php echo $web_control_value;?>">

                    </td>
                </tr>
            <?php } ?>

            <?php if($https_control){ ?>
                <tr>
                    <td style="width: 150px;">
                        <label>https<?php echo $this->language->get('text_app_action_action_text1');?>: </label>
                        <input type="checkbox" name="https_control_status"  value="1"<?php if($https_control_status) { ?> checked="checked" <?php } ?>>
                    </td>
                    <td>
                        <label class="control-label"><?php echo $this->language->get('text_app_action_action_text2');?> : </label>
                        <input type="text" <?php if($https_control_alter){ ?> disabled='disabled' <?php } ?> name="https_control_port_mapping" value="<?php echo $https_control_value;?>">
                    </td>
                </tr>
            <?php } ?>

            <?php if($mstsc_control){ ?>
                <tr>
                    <td style="width: 150px;">
                        <label>mstsc<?php echo $this->language->get('text_app_action_action_text1');?>:</label>
                        <input type="checkbox" name="mstsc_control_status" value="1"   <?php if($mstsc_control_status) { ?> checked="checked" <?php } ?>>
                    </td>
                    <td>
                        <label class="control-label"><?php echo $this->language->get('text_app_action_action_text2');?> :  </label>
                        <input type="text" <?php if($mstsc_control_alter){ ?> disabled='disabled' <?php } ?> name="mstsc_control_port_mapping" value="<?php echo $mstsc_control_value;?>">
                    </td>
                </tr>
            <?php } ?>

            <?php if($ssh_control){ ?>
                <tr>
                    <td style="width: 150px;">
                        <label> ssh<?php echo $this->language->get('text_app_action_action_text1');?>: </label>
                        <input type="checkbox" name="ssh_control_status"  value="1" <?php if($ssh_control_status) { ?> checked="checked" <?php } ?>>
                    </td>
                    <td>
                        <label class="control-label"><?php echo $this->language->get('text_app_action_action_text2');?> : </label>
                        <input type="text" <?php if($ssh_control_alter){ ?> disabled='disabled' <?php } ?> name="ssh_control_port_mapping" value="<?php echo $ssh_control_value;?>">
                    </td>
                </tr>
            <?php } ?>
            <?php if($webmail_control){ ?>
                <tr>
                    <td style="width: 150px;">
                        <label> Wev Mail<?php echo $this->language->get('text_app_action_action_text1');?>: </label>
                        <input type="checkbox" name="webmail_control_status"  value="1" <?php if($webmail_control_status) { ?> checked="checked" <?php } ?>>
                    </td>
                    <td>
                        <label class="control-label"><?php echo $this->language->get('text_app_action_action_text2');?> : </label>
                        <input type="text" <?php if($webmail_control_alter){ ?> disabled='disabled' <?php } ?> name="webmail_control_port_mapping" value="<?php echo $webmail_control_value;?>">
                    </td>
                </tr>
            <?php } ?>
            <?php if($web_redirect_control){ ?>
                <tr>
                    <td style="width: 150px;">
                        <label> Web Redirect<?php echo $this->language->get('text_app_action_action_text1');?>: </label>
                        <input type="checkbox" name="web_redirect_control_status"  value="1" <?php if($web_redirect_control_status) { ?> checked="checked" <?php } ?>>
                    </td>
                    <td>
                        <label class="control-label"><?php echo $this->language->get('text_app_action_action_text2');?> : </label>
                        <input type="text" <?php if($web_redirect_control_alter){ ?> disabled='disabled' <?php } ?> name="web_redirect_control_port_mapping" value="<?php echo $web_redirect_control_value;?>">
                    </td>
                </tr>
            <?php } ?>
            <?php if($web_work_control){ ?>
                <tr>
                    <td style="width: 150px;">
                        <label> Web Work<?php echo $this->language->get('text_app_action_action_text1');?>: </label>
                        <input type="checkbox" name="web_work_control_status"  value="1" <?php if($web_work_control_status) { ?> checked="checked" <?php } ?>>
                    </td>
                    <td>
                        <label class="control-label"><?php echo $this->language->get('text_app_action_action_text2');?> : </label>
                        <input type="text" <?php if($web_work_control_alter){ ?> disabled='disabled' <?php } ?> name="web_work_control_port_mapping" value="<?php echo $web_work_control_value;?>">
                    </td>
                </tr>
            <?php } ?>
            <?php if($pop3_control){ ?>
                <tr>
                    <td style="width: 150px;">
                        <label>pop3_control<?php echo $this->language->get('text_app_action_action_text1');?>: </label>
                        <input type="checkbox" name="pop3_control_status"  value="1" <?php if($pop3_control_status) { ?> checked="checked" <?php } ?>>
                    </td>
                    <td>
                        <label class="control-label"><?php echo $this->language->get('text_app_action_action_text2');?> : </label>
                        <input type="text" <?php if($pop3_control_alter){ ?> disabled='disabled' <?php } ?> name="pop3_control_port_mapping" value="<?php echo $pop3_control_value;?>">
                    </td>
                </tr>
            <?php } ?>

            <?php if($smtp_control){ ?>
                <tr>
                    <td style="width: 150px;">
                        <label>smtp_control<?php echo $this->language->get('text_app_action_action_text1');?>: </label>
                        <input type="checkbox" name="smtp_control_status"  value="1" <?php if($smtp_control_status) { ?> checked="checked" <?php } ?>>
                    </td>
                    <td>
                        <label class="control-label"><?php echo $this->language->get('text_app_action_action_text2');?> : </label>
                        <input type="text" <?php if($smtp_control_alter){ ?> disabled='disabled' <?php } ?> name="smtp_control_port_mapping" value="<?php echo $smtp_control_value;?>">
                    </td>
                </tr>
            <?php } ?>

            <?php if($imap_control){ ?>
                <tr>
                    <td style="width: 150px;">
                        <label>IAMP<?php echo $this->language->get('text_app_action_action_text1');?>: </label>
                        <input type="checkbox" name="imap_control_status"  value="1" <?php if($imap_control_status) { ?> checked="checked" <?php } ?>>
                    </td>
                    <td>
                        <label class="control-label"><?php echo $this->language->get('text_app_action_action_text2');?> : </label>
                        <input type="text" <?php if($imap_control_alter){ ?> disabled='disabled' <?php } ?> name="imap_control_port_mapping" value="<?php echo $imap_control_value;?>">
                    </td>
                </tr>
            <?php } ?>

            <?php if($server_control){ ?>
                <tr>
                    <td style="width: 150px;">
                        <label> Server<?php echo $this->language->get('text_app_action_action_text1');?>: </label>
                        <input type="checkbox" name="server_control_status"  value="1" <?php if($server_control_status) { ?> checked="checked" <?php } ?>>
                    </td>
                    <td>
                        <label class="control-label"><?php echo $this->language->get('text_app_action_action_text2');?> : </label>
                        <input type="text" <?php if($server_control_alter){ ?> disabled='disabled' <?php } ?> name="server_control_port_mapping" value="<?php echo $server_control_value;?>">
                    </td>
                </tr>
            <?php } ?>

            <?php if($file_server_control){ ?>
                <tr>
                    <td style="width: 150px;">
                        <label> File Server<?php echo $this->language->get('text_app_action_action_text1');?>: </label>
                        <input type="checkbox" name="file_server_control_status"  value="1" <?php if($file_server_control_status) { ?> checked="checked" <?php } ?>>
                    </td>
                    <td>
                        <label class="control-label"><?php echo $this->language->get('text_app_action_action_text2');?> : </label>
                        <input type="text" <?php if($file_server_control_alter){ ?> disabled='disabled' <?php } ?> name="file_server_control_port_mapping" value="<?php echo $file_server_control_value;?>">
                    </td>
                </tr>
            <?php } ?>

            <?php if($upgradesvr_control){ ?>
                <tr>
                    <td style="width: 150px;">
                        <label> Upgradesvr<?php echo $this->language->get('text_app_action_action_text1');?>: </label>
                        <input type="checkbox" name="upgradesvr_control_status"  value="1" <?php if($upgradesvr_control_status) { ?> checked="checked" <?php } ?>>
                    </td>
                    <td>
                        <label class="control-label"><?php echo $this->language->get('text_app_action_action_text2');?> : </label>
                        <input type="text" <?php if($upgradesvr_control_alter){ ?> disabled='disabled' <?php } ?> name="upgradesvr_control_port_mapping" value="<?php echo $upgradesvr_control_value;?>">
                    </td>
                </tr>
            <?php } ?>


            <?php if($SessionServer_control){ ?>
                <tr>
                    <td style="width: 150px;">
                        <label> SessionServer<?php echo $this->language->get('text_app_action_action_text1');?>: </label>
                        <input type="checkbox" name="SessionServer_control_status"  value="1" <?php if($SessionServer_control_status) { ?> checked="checked" <?php } ?>>
                    </td>
                    <td>
                        <label class="control-label"><?php echo $this->language->get('text_app_action_action_text2');?> : </label>
                        <input type="text" <?php if($SessionServer_control_alter){ ?> disabled='disabled' <?php } ?> name="SessionServer_control_port_mapping" value="<?php echo $SessionServer_control_value;?>">
                    </td>
                </tr>
            <?php } ?>

            <?php if($infoServer_control){ ?>
                <tr>
                    <td style="width: 150px;">
                        <label> InfoServer<?php echo $this->language->get('text_app_action_action_text1');?>: </label>
                        <input type="checkbox" name="infoServer_control_status"  value="1" <?php if($infoServer_control_status) { ?> checked="checked" <?php } ?>>
                    </td>
                    <td>
                        <label class="control-label"><?php echo $this->language->get('text_app_action_action_text2');?> : </label>
                        <input type="text" <?php if($infoServer_control_alter){ ?> disabled='disabled' <?php } ?> name="infoServer_control_port_mapping" value="<?php echo $infoServer_control_value;?>">
                    </td>
                </tr>
            <?php } ?>

            <?php if($offmsgsvr_control){ ?>
                <tr>
                    <td style="width: 150px;">
                        <label> Offmsgsvr<?php echo $this->language->get('text_app_action_action_text1');?>: </label>
                        <input type="checkbox" name="offmsgsvr_control_status"  value="1" <?php if($offmsgsvr_control_status) { ?> checked="checked" <?php } ?>>
                    </td>
                    <td>
                        <label class="control-label"><?php echo $this->language->get('text_app_action_action_text2');?> : </label>
                        <input type="text" <?php if($offmsgsvr_control_alter){ ?> disabled='disabled' <?php } ?> name="offmsgsvr_control_port_mapping" value="<?php echo $offmsgsvr_control_value;?>">
                    </td>
                </tr>
            <?php } ?>
            </table>

        <div style="clear: both;"></div>
            <?php if($db_mysql){ ?>
        <hr>

        <table>
                            <h2><?php echo $this->language->get('text_app_dbset_title');?></h2>
                                <tr>
                                    <td><label class="control-label"><?php echo $this->language->get('text_item_db_name');?>: <span class="required">*</span></label><input type="text" name="mysql_db_name" value="<?php echo $mysql_db_name;?>"></td>
                                    <td><label class="control-label"><?php echo $this->language->get('text_item_db_user');?> :<span class="required">*</span></label> <input type="text" name="mysql_db_user" value="<?php echo $mysql_db_user;?>"></td>
                                </tr>
                                <tr>
                                    <td><label class="control-label"><?php echo $this->language->get('text_item_db_password');?> : <span class="required">*</span></label><input type="text" name="mysql_db_password" value="<?php echo $mysql_db_password;?>"></td>
                                    <td><label class="control-label"><?php echo $this->language->get('text_item_db_root_password');?> : <span class="required">*</span></label><input type="text" name="mysql_root_password" value="<?php echo $mysql_root_password;?>"></td>
                                </tr>

                        </table>
            <?php } ?>

        <div style="clear: both;"></div>
        <?php if($windows_server_ad){ ?>
        <hr>

        <table>
            <h2>AD</h2>
            <tr>
                <td><label class="control-label">Window Domain Name: <span class="required">*</span></label><input type="text" name="windows_domain_name" value="<?php echo $windows_domain_name;?>"></td>
                <td><label class="control-label">Window Netbios Name :<span class="required">*</span></label> <input type="text" name="windows_netbios_name" value="<?php echo $windows_netbios_name;?>"></td>
            </tr>
            <tr>
                <td><label class="control-label">Window Safe Admin Password:<span class="required">*</span></label><input type="text" name="windows_safe_admin_password" readonly="readonly" value="<?php echo $windows_safe_admin_password;?>"></td>
            </tr>

        </table>
        <?php } ?>

            <input type="hidden" name="vpc_name" value="<?php echo $vpc_name;?>">
            <input type="hidden" name="subnet_name" value="<?php echo $subnet_name;?>"/>
            <input type="hidden" name="app_id" value="<?php echo $app_id;?>">
    </div>
       <div class="modal-footer ">
                <button aria-hidden="true" data-dismiss="modal" class="btn close"  onclick="empty_app_config_dialog();"><?php echo $this->language->get('button_cancel');?></button>
                <button aria-hidden="true" id="app_config_submit_btn" class="btn green btn-primary " type="button" value="<?php echo $app_id;?>"><i class="icon-ok"></i><?php echo $this->language->get('button_continue');?></button>
        </div>

</div>

<script>
    $(document).keyup(function(event){
        if(event.keyCode ==13){
            $("#app_config_submit_btn").click();
        }
    });
    $(function(){

        fill_login_option();
        $("#os_type").change(function(){
            if($(this).val().indexOf("windows") >= 0){
//                $("#app_login_sshkey").hide();
//                $("#app_login_password").show();

                $("#app_select_login_type").empty();
                $("#app_select_login_type").append('<option value="password" selected="selected">密码方式</option>');
                $("#app_select_login_type").change();
            }
            else{
                $("#app_select_login_type").empty();
                $("#app_select_login_type").append('<option value="password" selected="selected">密码方式</option>');
                $("#app_select_login_type").append('<option value="ssh_public_key">SSH密钥对</option>');

                $("#app_select_login_type").change();
            }

        });
    	//select login type
    	 $("#app_select_login_type").change(function(){

    	 	 if($(this).val() == "password"){
    	 	   $("#app_login_sshkey").hide();
    	 	   $("#app_login_password").show();

    	 	 }
    	 	 else if($(this).val() == "ssh_public_key"){
    	 	   $("#app_login_password").hide();
    	 	   $("#app_login_sshkey").show();
    	 	   fetch_app_ssh_key("#app_select_sshkey_name");

    	 	 }
    	 	 else{
    	 	   $("#app_login_sshkey").hide();
    	 	   $("#app_login_password").show();

    	 	 }
    	 });


        //check app name exists
        $('input[name=\'app_name\']').change(function(){
            var ef=$(this);
            $.ajax({
                url: '<?php echo $check_app_name_exist;?>',
                cache: false,
                dataType: 'json',
                type: 'POST',
                data: {
                    apptype: $('input[name=\'app_id\']').val(),
                    appname: $(this).val()
                },
                beforeSend: function() {
                    ef.next().after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
                },
                complete: function() {
                    $('.wait').remove();
                },
                success: function(json) {
                    if(json['result']=='success'){
                        ef.removeClass("success");
                        ef.removeClass("error");
                        ef.addClass("success");
                    }else{
                        ef.removeClass("success");
                        ef.removeClass("error");
                        ef.addClass("error");
                    }
                }
            });
        });


        getprice();
    });
    $('select[name=\'host_type\']').change(function(){
        getprice();
    });

   function getprice(){
       $.ajax({
           url: '<?php echo $get_price_action;?>',
           cache: false,
           dataType: 'json',
           type: 'POST',
           data: {
               region: $('input[name=\'region\']').val(),
               host_type: $('select[name=\'host_type\']').val(),
               os_type: $('select[name=\'os_type\']').val(),
               vpc_name: $('#appconfig_form-'+ $('input[name=\'app_id\']').val()+' input[name=\'vpc_name\']').val(),
               app_id: $('input[name=\'app_id\']').val()
           },
           success: function(json) {
             $("#price_1").html(json['text']);
             $("#price_2").val(json['val']);

           }
       });
   }
   //get ssh key pair from api server
   function fetch_app_ssh_key(select_id){
    //var base = neucloud_api_server;
	$(select_id).empty();
	$.ajax({
		type: "post",
		dataType: "json",
		url:'index.php?route=deploy/app_config/fetch_app_ssh_key',
		data: {
		    region: $('#region').val()

		},
		cache: false,
		async: false,
		success: function(msg){
			var data = msg._items;
			$.each(data, function(i, n){
				var content = '<option value="'+n.name+'">'+n.name+'</option>';
				$(select_id).append(content);
			});
		}

	});
}

    function fill_login_option(){

       if($("#os_type").val().indexOf("windows") >= 0){
         $("#app_select_login_type").empty();
         $("#app_select_login_type").append('<option value="password" selected="selected">密码方式</option>');
       }
    }

    function empty_app_config_dialog(){

        var aid = $('input[name=\'app_id\']').val();
        $('#appconfig_form-'+aid).trigger('close');
        $('#appconfig_form-'+aid).empty();

    }






</script>